package storage.v1;

import com.onpositive.data.IPropertyConstants;
import com.onpositive.knowledge.model.IThing;
import com.onpositive.mediawiki.propertyparser.ParsedDocument;
import com.onpositive.mediawiki.propertyparser.PropertyCharacteristic;
import com.onpositive.semantic.model.api.meta.BaseMeta;
import com.onpositive.semantic.model.api.meta.IMeta;
import com.onpositive.semantic.model.api.property.IProperty;
import com.onpositive.units.ParsedString;

public class DefaultPictureProperty implements IProperty {

	public static final String DEFAULT_PICTURE_PROPERTY_NAME = "default-picture" ;
		
	private IWikiStorage storage;
	private BaseMeta meta ;

	public DefaultPictureProperty( IWikiStorage storage )
	{
		super();
		this.storage = storage;
		meta = new BaseMeta() ;
		meta.putMeta( PropertyCharacteristic.CHAR_PARSER_ID_LABEL, ParsedString.ID ) ;
		meta.putMeta( PropertyCharacteristic.CHAR_PROPERTY_NAME_LABEL, DEFAULT_PICTURE_PROPERTY_NAME ) ;
		meta.putMeta(IPropertyConstants.CHAR_IS_SERVICE_PROPERTY, true );
	}

	@Override
	public String getId() {

		return DEFAULT_PICTURE_PROPERTY_NAME;
	}

	@Override
	public Object getValue(Object obj) {
		
		if (obj instanceof IThing) {
			obj = ((IThing) obj).getId();
		}
		if (obj instanceof String) {
			String id = (String) obj;
			ParsedDocument parsedDocument = storage.getParsedDocument(id);
			if (parsedDocument != null)
				return parsedDocument.getDefaultPicture() ;
			
		}
		return null;
	}

	@Override
	public IMeta getMeta() {

		return meta;
	}

}
